// CommandLineHelper Library
// =========================
// License: Microsoft Permissive License (Ms-PL) v1.1
// Author: Rhy Mednick (http://www.rhyverse.net)
// Project Site: http://www.codeplex.com/CommandLineHelper

using System;
using System.Collections.Generic;
using System.Text;

namespace CommandLineHelper.Attributes
{
    /// <summary>
    /// When applied to a property, this attribute instructs the command line helper parsing routine to validate 
    /// that the property value passed in is not null.
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
    public sealed class ValidateNotNullAttribute : Attribute, IValidation
    {
        private string m_statusMessage = String.Empty;

        /// <summary>
        /// Gets the status message that is set when the IsValid() method is called.
        /// </summary>
        public string StatusMessage
        {
            get
            {
                return m_statusMessage;
            }
        }

        /// <summary>
        /// Verifies that the passed in value is not null.
        /// </summary>
        /// <param name="value">The value to validate.</param>
        /// <returns>True if the value is not null and false if it is.</returns>
        public bool IsValid(object value)
        {
            bool retval = false;
            if (value == null)
            {
                m_statusMessage = "The property is set to a null value.";
            }
            else
            {
                retval = true;
            }
            return retval;
        }

    }

}
